<template>
    <view>
        <c-list-filter ref="filter" @filter="onFilter" @sxfilter="sxfilter"></c-list-filter>
        <view class="ptr-list" :class="{ ptrsearch: false }">
            <block v-if="zwlist && zwlist.length > 0">
                <view v-for="(item, index) in zwlist" :key="index">
                    <li-job :item="item" :page="page"></li-job>
                    <block></block>
                </view>
            </block>
            <view class="nothing" v-if="zwlist.length == 0">
                <image src="/static/img/nothing.png" />
                <view style="text-align:center">暂无相关数据</view>
            </view>
        </view>
    </view>
</template>

<script>
import cListFilter from '../c/c-list-filter.vue';
import liJob from '../c/li-job.vue';
export default {
    name: 'ay-myjob-list',
    components: {
        cListFilter,
        liJob
    },
    data() {
        return {
            page: 'ay-apply',
            reload: false,
            zwlist: [],
            form: {
                pagenum: 10,
                type: 0,
                area: '',
                place: ''
            }
        };
    },
    created() {
        uni.$on('jobStatusChange', this.jobStatusChange);
    },
    destroyed() {
        uni.$off('jobStatusChange');
    },
    methods: {
        jobStatusChange(e) {
            if (this.page != e.page) {
                return;
            }
            console.log(e);
            if (e.refresh) {
                this.refresh();
                return;
            }
            let pos = -1;
            this.zwlist.forEach((item, index) => {
                if (item.publishList.publish_id == e.publish_id) {
                    pos = index;
                    if (e.remove) {
                        return;
                    }
                    if (e.job_status) {
                        item.job_status = e.job_status;
                    }
                    if (e.job_process) {
                        item.job_process = e.job_process;
                    }
                }
            });
            if (e.remove && pos >= 0) {
                this.zwlist.splice(pos, 1);
            }
        },
        async loadData() {
            if (!this.$global.sessionkey) {
                return;
            }
            this.form.pages++;
            let res = await this.$request.post({
                url: '/aunt/applyList',
                data: this.form
            });
            if (this.reload) {
                this.zwlist = res || [];
            } else {
                this.zwlist = this.zwlist.concat(res);

            }
            this.reload = false;
            uni.stopPullDownRefresh();
            console.log('sqlist', this.zwlist);
        },
        refresh() {
            this.reload = true;
            this.form.pages = 0;
            this.$refs.filter.setQY();
            this.loadData();
        },
        loadMore() {
            this.loadData();
        },
        show() {
            if (this.zwlist === undefined || this.zwlist.length == 0) {
                this.refresh();
            }
        },
        onFilter(e) {
            console.log('filter', e);
            Object.assign(this.form, e);
            this.zwlist = [];
            this.form.pages = 0;
            this.loadData();
        },
        sxfilter() {
            this.$emit('sxfilter', this.form);
            console.log('点击筛选2');
        }
    }
};
</script>

<style></style>
